package com.hu.zhcc.shiro.controller;

import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.entity.bo.Index;
import com.hu.zhcc.shiro.entity.vo.IndexVO;
import com.hu.zhcc.shiro.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 体质评估
 */

@RestController
@CrossOrigin
@RequestMapping("/indexs")
public class IndexController {
    @Autowired
    private IndexService indexService;

    @GetMapping("")
    @ResponseBody
    public PageInfo<Index> homeIndex(IndexVO indexVO){
        PageInfo<Index> indexPageInfo = indexService.pageQuery(indexVO);
        return indexPageInfo;
    }

    @PostMapping("")
    public ResponseEntity<?> saveCheckitem(@RequestBody Index index) {
        return indexService.AddIndex(index) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }
    @DeleteMapping("/{id}")
    public ResponseEntity<?> removeIndex(@PathVariable("id") Short id) {
        return indexService.removeIndex(id) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }

    @PutMapping("/{id}")
    public ResponseEntity<Integer> updateRouter(@PathVariable("id") int id, @RequestBody Index index) {
        return indexService.updateIndex(index) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }
}
